<?php

namespace app\store\model;

use think\Model;

class GroupGoodsItem extends Model
{
    protected $schema = [
        'id' => 'int',
        'group_goods_id' => 'int',
        'attr' => 'string',
        'image' => 'string',
        'market_price' => 'float',
        'sell_price' => 'float',
        'group_price' => 'float',
        'stock' => 'int',
    ];

    public function setAttrAttr($value)
    {
        return join(';',$value);
    }

    public function getAttrAttr($value)
    {
        return explode(';',rtrim($value,';'));
    }


    public function groupGoods()
    {
        return $this->belongsTo(GroupGoods::class)->field('id,group_activity_id,goods_name,main_image');
    }

    public function activity()
    {
        return $this->belongsTo(GroupActivity::class);
    }
}